package ${servicePackage}.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import ${mapperPackage}.${modelName}Mapper;
import ${modelPackage}.${modelName};
import ${servicePackage}.${modelName}Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName ${modelName}ServiceImpl
 * @Description ${modelName},主要对${modelName}类型数据的业务服务操作实现类
 * @Company ${company}
 * @Author ${author}
 * @Email ${email}
 * @Date ${ .now?string("yyyy/MM/dd hh:mm:ss")}
 * @Version 1.0
 **/
@Service
public class ${modelName}ServiceImpl implements ${modelName}Service {
    @Autowired
    ${modelName}Mapper ${modelName?uncap_first}Mapper;
    @Override
    public String insert(${modelName} ${modelName?uncap_first}) {
        String uid = UUID.randomUUID().toString();
        ${modelName?uncap_first}.setUid(uid);
        ${modelName?uncap_first}.setDelFlag("0");
        ${modelName?uncap_first}.setCreateTime(new Date());
        ${modelName?uncap_first}Mapper.insert(${modelName?uncap_first});
        return uid;
    }

    @Override
    public Integer update(${modelName} ${modelName?uncap_first}) {
        ${modelName?uncap_first}.setUpdateTime(new Date());
        return ${modelName?uncap_first}Mapper.update(${modelName?uncap_first});
    }

    @Override
    public Integer  delete(String uid) {
        return ${modelName?uncap_first}Mapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return ${modelName?uncap_first}Mapper.batchDelete(uids);
    }

    @Override
    public ${modelName} get(String uid) {
        return ${modelName?uncap_first}Mapper.get(uid);
    }

    @Override
    public List<${modelName}> list(${modelName} ${modelName?uncap_first}) {
    return  ${modelName?uncap_first}Mapper.list(${modelName?uncap_first});
    }

    @Override
    public PageInfo<${modelName}> getPagingData(int offset, int limit,String orderBy, ${modelName} ${modelName?uncap_first}) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<${modelName}> pageInfo =new PageInfo<>(${modelName?uncap_first}Mapper.list(${modelName?uncap_first}));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(${modelName} ${modelName?uncap_first}){
        if(null!=${modelName?uncap_first}.getUid()){
            this.update(${modelName?uncap_first});
        }else{
            this.insert(${modelName?uncap_first});
        }
        return ${modelName?uncap_first}.getUid();
    }
            }
